package com.zyh.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/code")
public class CheckCodeController {
    @RequestMapping("/checkCode")
    public void checkCode(HttpSession httpSession,HttpServletResponse httpServletResponse) throws Exception{
        LineCaptcha captcha = CaptchaUtil.createLineCaptcha(200,100);
//      根据验证码对象获取对应的文本
        String checkCode = captcha.getCode();
        httpSession.setAttribute("checkCode",checkCode);
        ServletOutputStream sos = httpServletResponse.getOutputStream();
        captcha.write(sos);
    }
}
